package com.carassistant.beta.music.dialog;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.carassistant.beta.R;
import com.carassistant.beta.common.Consts;

/**
 * @fMessageDialog.java 自定义内容对话框
 * @author thinkpad
 * @time2014-1-22
 * 
 */
public class MessageDialog extends MessageAnimDialog implements
		android.view.View.OnClickListener {

	private String title = "";// 对话框标题
	private String content = "";// 对话框内容
	private TextView title_tv;
	private TextView content_tv;
	private Button button_ok;
	private Button button_no;
	private int dialogId=0;
	private int layoutId=0;
	//listview类型的对话框
	private MessageListAdapter adapter;
	private ListView listview;
	protected MessageDialog(Context context, boolean cancelable,
			OnCancelListener cancelListener) {
		super(context, cancelable, cancelListener);
		
	}

	/**
	 * @param context 上下文
	 * @param listener 监听
	 * @param dialogId 传递Consts.MESSAGE_ONLY，可以隐藏取消按钮
	 * @param title 标题
	 * @param content 内容
	 */
	public MessageDialog(Context context,
			OnTVAnimDialogDismissListener listener, int dialogId, String title,
			String content,int layoutId) {
		super(context, listener, dialogId, title, content, layoutId);
		this.dialogId=dialogId;
		this.title=title;
		this.content=content;
		this.layoutId=layoutId;
	}

	@Override
	public void setOnDismissListener(OnDismissListener listener) {
		super.setOnDismissListener(listener);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		System.out.println("onCreate========");
		setContentView(layoutId);
		switch (layoutId) {
		case R.layout.message_dialog:
			title_tv = (TextView) findViewById(R.id.tv_title);
			content_tv = (TextView) findViewById(R.id.content_tv);
			title_tv.setText(title);
			content_tv.setText(content);
			button_ok = (Button) findViewById(R.id.button_ok);
			button_no = (Button) findViewById(R.id.button_no);
			button_ok.setOnClickListener(this);
			button_no.setOnClickListener(this);
			if(dialogId==Consts.MESSAGE_ONLY){
				button_no.setVisibility(View.GONE);
				button_ok.setWidth(LayoutParams.MATCH_PARENT);
			}
			break;

		case R.layout.message_listview:
			View v=findViewById(R.layout.message_listview);
			listview=(ListView) v.findViewById(R.id.listview);
			listview.setAdapter(adapter);
			break;
		}

	}
	public void setAdpater(){
		
	}
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.button_ok:
			setDialogId(Consts.MESSAGE_OK);// 确定
			break;

		case R.id.button_no:
			setDialogId(Consts.MESSAGE_NO);// 取消
			break;
		}
		dismiss();// 调用父类
	}

}
